//index.js

var app = getApp()
Page({
  data: {
    feed: [],
    feed_length: 0,
    jsonresult: '',
    sourceUrl:'https://eis.natappvip.cc/ITSupport',
    queUrl: '../../image/que.png',
    searchContent:"",
  },
  //事件处理函数
  bindItemTap: function (e) {
    var knowledgeId = e.currentTarget.dataset.knowledgeId
    wx.navigateTo({
      url: '../knowledgeDetail/knowledgeDetail?knowledgeId=' + this.data.knowledgeId
    })
  },
  onLoad: function (options) {
    console.log('onLoad')
    this.setData({
      searchContent: options.searchContent,
    })
    //调用应用实例的方法获取全局数据
    this.search();
  },

  search: function () {
    var that = this
    if (this.data.searchContent != ""){
      wx.request({
        url: 'https://eis.natappvip.cc/ITSupport/knowledge_getAllKnowledgeBySearchContent.action',
        data: {
          'searchContent': this.data.searchContent,
        },
        header: {
          'Content-Type': 'application/json'
        },
        success: function (res) {
          let jsonresult = JSON.parse(res.data)
          console.log(jsonresult.result)
          if (jsonresult.result == "error") {
            that.setData({
              feed_length: 0
            })
          } else {
            that.setData({
              feed: jsonresult.knowledges,
              feed_length: jsonresult.knowledges.length
            })
          }
        },
        fail: function (res) {
          console.log("failed:" & res)
        }
      })
    }
  },
  
})
